// SetThreshold.cpp : implementation file

#include "stdafx.h"
#include "Virtual Pole.h"
#include "SetThreshold.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSetThreshold dialog

CSetThreshold::CSetThreshold(CWnd* pParent /*=NULL*/)
	: CDialog(CSetThreshold::IDD, pParent)
	, m_bEnableFrequencyTrigger(FALSE)
	, m_bEnableProximityTrigger(TRUE)
	, m_lFreqSNRThreshold(0)
	, m_lFrequencyBandpassLow(0)
	, m_lFrequencyBandpassHigh(0)
	, m_bLimitMotionToObjects(FALSE)
	, m_csTrackingOutputCh1(_T(""))
	, m_csEventTriggerCh(_T(""))
	, m_csEventTriggerDev(_T(""))
	, m_bDetectMotion(false)
	, m_csIndicatorTriggerINCh(_T(""))
{
	//{{AFX_DATA_INIT(CSetThreshold)
	m_bCheckMedian = FALSE;
	m_bLimitMotionToObjects = FALSE;
	m_bDetectMotion = FALSE;
	m_bEnableFrequencyTrigger = FALSE;
	m_bEnableProximityTrigger = TRUE;
	m_lFreqSNRThreshold = 2;
	m_lFrequencyBandpassLow = 5;
	m_lFrequencyBandpassHigh = 15;
	//}}AFX_DATA_INIT
}

void CSetThreshold::DoDataExchange(CDataExchange* pDX) {
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetThreshold)
	DDX_Control(pDX, IDC_SPIN_Median_Threshold, m_spinMedianThreshold);
	DDX_Control(pDX, IDC_SPIN_Motion, m_spinMotion);
	DDX_Control(pDX, IDC_SPIN_Pole, m_spinPole);
	DDX_Text(pDX, IDC_EDIT_Motion, m_iMotion_val);
	DDV_MinMaxInt(pDX, m_iMotion_val, 1, 255);
	DDX_Text(pDX, IDC_EDIT_Pole, m_iPole_val);
	DDV_MinMaxInt(pDX, m_iPole_val, 1, 100);
	DDX_Text(pDX, IDC_EDIT_Median_Threshold, m_iMedianThreshold);
	DDV_MinMaxUInt(pDX, m_iMedianThreshold, 0, 1000);
	DDX_Check(pDX, IDC_CHECK_LIMIT_MOTION_TO_OBJECTS, m_bLimitMotionToObjects);
	DDX_Check(pDX, IDC_CHECK_DETECT_MOTION, m_bDetectMotion);
	//}}AFX_DATA_MAP
	DDX_Check(pDX, IDC_CHECK_FrequencyDetection, m_bEnableFrequencyTrigger);
	DDX_Check(pDX, IDC_CHECK_EnableProximityTrigger, m_bEnableProximityTrigger);
	DDX_Text(pDX, IDC_EDIT_FrequencySNRThreshold, m_lFreqSNRThreshold);
	DDX_Text(pDX, IDC_EDIT_FrequencyBandpassLow, m_lFrequencyBandpassLow);
	DDX_Text(pDX, IDC_EDIT_FrequencyBandpassHigh, m_lFrequencyBandpassHigh);
	DDX_CBString(pDX, IDC_TRACKOUTPUTCH01, m_csTrackingOutputCh1);
	DDX_CBString(pDX, IDC_EVENTTRIGCH, m_csEventTriggerCh);
	DDX_CBString(pDX, IDC_EVENTTRIGDEV, m_csEventTriggerDev);
	DDX_CBString(pDX, IDC_INDICATORTRIGINCH, m_csIndicatorTriggerINCh);
}

BEGIN_MESSAGE_MAP(CSetThreshold, CDialog)
	//{{AFX_MSG_MAP(CSetThreshold)
	ON_EN_CHANGE(IDC_EDIT_Motion, OnUpdateEdit)
	ON_BN_CLICKED(IDAPPLY, OnApply)
	ON_EN_CHANGE(IDC_EDIT_Pole, OnUpdateEdit)
	ON_EN_CHANGE(IDC_EDIT_Speed, OnUpdateEdit)
	//}}AFX_MSG_MAP
	ON_STN_CLICKED(IDC_Pole_ex, &CSetThreshold::OnStnClickedPoleex)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_Pole, &CSetThreshold::OnDeltaposSpinPole)
	ON_STN_CLICKED(IDC_Motion_Text, &CSetThreshold::OnStnClickedMotionText)
	ON_BN_CLICKED(IDC_Pole, &CSetThreshold::OnBnClickedPole)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_Motion, &CSetThreshold::OnDeltaPosSpinMotion)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetThreshold message handlers

BOOL CSetThreshold::OnInitDialog() {
	CDialog::OnInitDialog();

	// Recall window position
	if (m_lpwndpl.rcNormalPosition.bottom > 0)
		SetWindowPlacement(&m_lpwndpl);

	m_bApplay = false;

	// Config spin controls
	m_spinMotion.SetDecimalPlaces (0);
	m_spinMotion.SetTrimTrailingZeros (true);
	m_spinMotion.SetRangeAndDelta (1, 255, 1);
	m_spinMotion.SetPos (m_iMotion_val);

	m_spinPole.SetDecimalPlaces (0);
	m_spinPole.SetTrimTrailingZeros (true);
	m_spinPole.SetRangeAndDelta (1, 100, 1);
	m_spinPole.SetPos (m_iPole_val);

	m_spinMedianThreshold.SetDecimalPlaces (0);
	m_spinMedianThreshold.SetTrimTrailingZeros (true);
	m_spinMedianThreshold.SetRangeAndDelta (0, 1000, 1);
	m_spinMedianThreshold.SetPos(m_iMedianThreshold);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetThreshold::OnUpdateEdit() {
	UpdateData();
}

void CSetThreshold::OnChangeEDITPole() {
}

void CSetThreshold::OnApply() {
	m_bApplay = true;
	OnOK();
}

void CSetThreshold::OnOK() {
	CDialog::OnOK();
	// Remember window position
	GetWindowPlacement(&m_lpwndpl);
}

void CSetThreshold::OnStnClickedPoleex() {
}

void CSetThreshold::OnDeltaposSpinPole(NMHDR *pNMHDR, LRESULT *pResult) {
	LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
	*pResult = 0;
}


void CSetThreshold::OnStnClickedMotionText() {
}

void CSetThreshold::OnBnClickedPole() {
}

void CSetThreshold::OnDeltaPosSpinMotion(NMHDR *pNMHDR, LRESULT *pResult) {
	LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
	*pResult = 0;
	OnApply();
}
